<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>快递员管理</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
</head>
<body>
<div th:replace="~{common/navbar :: navbar}"></div>

<div class="container mt-4">
    <h2 class="mb-4"><i class="bi bi-person-badge"></i> 在职快递员管理</h2>

    <div class="card">
        <div class="card-header">
            当前注册快递员（共 <span th:text="${#lists.size(users)}">0</span> 人）
        </div>

        <table class="table table-hover">
            <thead class="table-light">
            <tr>
                <th>工号</th>
                <th>姓名</th>
                <th>注册邮箱</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="user : ${users}" th:if="${not #lists.isEmpty(users)}">
                <td th:text="${user.userID}">CU001</td>
                <td th:text="${user.userName}">张三</td>
                <td th:text="${user.email ?: '未填写'}">zhangsan@example.com</td>
                <td>
                    <!-- 修正后的按钮 -->
                    <button class="btn btn-danger btn-sm btn-delete"
                            data-userid="${user.userID}"
                            onclick="handleDelete(this)">
                        <i class="bi bi-person-dash"></i> 辞退
                    </button>
                </td>
            </tr>
            <tr th:if="${#lists.isEmpty(users)}">
                <td colspan="4" class="text-center text-muted">暂无注册快递员</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<!-- 添加JavaScript处理 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
    function handleDelete(button) {
        const userId = button.dataset.userid;
        if (confirm(`确定要辞退快递员 ${userId} 吗？`)) {
            window.location.href = `/admin/users/delete/${userId}`;
        }
    }
</script>
</body>
</html>